﻿@namespace AntDesign.Pro.Template
@inherits LayoutComponentBase

<AntDesign.ProLayout.BasicLayout Logo="@("https://gw.alipayobjects.com/zos/rmsportal/KDpgvguMpGfqaHPjicRK.svg")"
                                 MenuData="MenuData"
                                 MenuAccordion
                                 Collapsed="collapsed"
                                 OnCollapse="e=>collapsed=e">
    <HeaderContentRender>
        <Space Size="@("24")">
            <SpaceItem>
                <Icon Class="action" Type="@(collapsed?"menu-unfold":"menu-fold")" OnClick="Toggle" />
            </SpaceItem>
            <SpaceItem>
                <Icon Class="action" Type="reload" Theme="outline" OnClick="Reload" />
            </SpaceItem>
        </Space>
    </HeaderContentRender>
    <RightContentRender>
        <AntDesign.Pro.Template.Components.RightContent />
    </RightContentRender>
    <ChildContent>
        <ReuseTabs></ReuseTabs>
        @*  @Body *@
    </ChildContent>
    <FooterRender>
        <FooterView Copyright="2021 Ant Design Blazor" Links="Links"></FooterView>
    </FooterRender>
</AntDesign.ProLayout.BasicLayout>
<SettingDrawer />

@inject HttpClient HttpClient
@inject ReuseTabsService TabService;
@code
{
    bool collapsed;

    private MenuDataItem[] MenuData { get; set; } = { };

    protected override async Task OnInitializedAsync()
    {
        await base.OnInitializedAsync();
        MenuData = await HttpClient.GetFromJsonAsync<MenuDataItem[]>("data/menu.json");

        // workaround for the reusetabs issue that can't open the default page.
        // will fix in next release. https://github.com/ant-design-blazor/ant-design-blazor/pull/3519
        TabService.ReloadPage();
    }

    public LinkItem[] Links { get; set; } =
    {
        new LinkItem
        {
            Key = "Ant Design Blazor",
            Title = "Ant Design Blazor",
            Href = "https://antblazor.com",
            BlankTarget = true,
        },
        new LinkItem
        {
            Key = "github",
            Title = (RenderFragment)(@<Icon Type="github" />),
            Href = "https://github.com/ant-design-blazor/ant-design-pro-blazor",
            BlankTarget = true,
        },
        new LinkItem
        {
            Key = "Blazor",
            Title = "Blazor",
            Href = "https://dotnet.microsoft.com/apps/aspnet/web-apps/blazor?WT.mc_id=DT-MVP-5003987",
            BlankTarget = true,
        }
    };

    void Toggle()
    {
        collapsed = !collapsed;
    }

    void Reload()
    {
        TabService.ReloadPage();
    }
}